package Q2;

import java.util.Scanner;

public class Main {

    public static int n;
    public static int m;
    public static int[] acid;
    public static int[] sweet;

    public static long retAcid;
    public static long retSweet;
    public static long ret;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        n = scanner.nextInt();
        m = scanner.nextInt();
        acid = new int[n];
        sweet = new int[n];

        for (int i = 0; i < n; i++) {
            acid[i] = scanner.nextInt();
        }

        for (int i = 0; i < n; i++) {
            sweet[i] = scanner.nextInt();
        }

        dfs(new boolean[n], 0, 0, 0);

        System.out.println(retAcid + " " + retSweet);

    }

    /**
     *
     * @param flag
     * @param index
     * @param count 已经吃了几个水果
     * @param temp 最后的酸度与甜度之和
     */
    public static void dfs(boolean[] flag, int index, int count, long temp) {
        if (count == m) {
            if (ret <= temp) {
                long tempAcid = 0;
                long tempSweet = 0;
                for (int i = 0; i < n; i++) {
                    if (flag[i]) {
                        //吃了这个水果
                        tempAcid += acid[i];
                        tempSweet += sweet[i];
                    }
                }

                if (ret < temp || tempAcid < retAcid) {
                    retAcid = tempAcid;
                    retSweet = tempSweet;
                    ret = temp;
                }
                return;
            }
        }

        if (index == n) {
            return;
        }

        for (int i = index; i < n; i++) {
            if (!flag[i]) {
                //选
                flag[i] = true;
                dfs(flag, i + 1, count + 1, temp + (sweet[i] - acid[i]));
                //回溯
                flag[i] = false;

                //不选
                dfs(flag, i + 1, count, temp);
            }
        }
    }
}
